<?php

namespace app\common\service;

class TimeService
{
    public static function today($str = false)
    {
        $Ymd = date("Y-m-d", time());
        if (!$str) {
            return [$Ymd . " 00:00:00", $Ymd . " 23:59:59"];
        } else {
            return [strtotime($Ymd . " 00:00:00"), strtotime($Ymd . " 23:59:59")];
        }
    }

    public static function yesterday($str = false)
    {
        $Ymd = date("Y-m-d", time() - 86400);
        if (!$str) {
            return [$Ymd . " 00:00:00", $Ymd . " 23:59:59"];
        } else {
            return [strtotime($Ymd . " 00:00:00"), strtotime($Ymd . " 23:59:59")];
        }
    }

    public static function month($str = false)
    {
        $startTime = date('Y-m-01', time());//获取该月份的第一天
        $endTime = date('Y-m-t', time());//获取该月份的最后一天
        if (!$str) {
            return [$startTime . " 00:00:00", $endTime . " 23:59:59"];
        } else {
            return [strtotime($startTime . " 00:00:00"), strtotime($endTime . " 23:59:59")];
        }
    }

    public static function lastMonth($str = false)
    {
        $startTime = date('Y-m-01', strtotime('-1 month'));//获取该月份的第一天
        $endTime = date('Y-m-t', strtotime(-date('d') . 'day'));//获取该月份的最后一天
        if (!$str) {
            return [$startTime . " 00:00:00", $endTime . " 23:59:59"];
        } else {
            return [strtotime($startTime . " 00:00:00"), strtotime($endTime . " 23:59:59")];
        }
    }

}